package com.cnsugar.common.jdbc.utils;

/**
 * @Author Sugar
 * @Version 2018/7/23 17:50
 */
public class ArrayUtils {
    /**
     * 是否在数组中
     *
     * @param array
     * @param str
     * @return
     */
    public static boolean isInArray(String str, String[] array) {
        for (String s : array) {
            if (s.equalsIgnoreCase(str)) {
                return true;
            }
        }
        return false;
    }

    /**
     * 数组截取
     *
     * @param arr
     * @param len
     * @return
     */
    public static int[] subArray(int[] arr, int len) {
        if (arr.length <= len) {
            return arr;
        }
        int[] newArr = new int[len];
        for (int i = 0; i < len; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }

    /**
     * 数组截取
     *
     * @param arr
     * @param len
     * @return
     */
    public static Object[] subArray(Object[] arr, int len) {
        if (arr.length <= len) {
            return arr;
        }
        Object[] newArr = new Object[len];
        for (int i = 0; i < len; i++) {
            newArr[i] = arr[i];
        }
        return newArr;
    }
}
